package net.tt.util;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.*;

/**
 * EXCEL文件辅助类
 *
 * @author tbc on 2016/11/27 0:25.
 */
public class ExcelFileHelper {
    public static File loadFile(String filePath) {
        return new File(filePath);
    }

    public static InputStream loadFile(File file) throws FileNotFoundException {
        return new FileInputStream(file);
    }

    public static XSSFWorkbook createXSSFWorkbook(InputStream inputStream) throws IOException {
        return new XSSFWorkbook(inputStream);
    }

    public static XSSFWorkbook getXSSFWorkbook(String file) throws IOException {
        return createXSSFWorkbook(loadFile(loadFile(file)));
    }

    public static void write(XSSFWorkbook wb, XSSFSheet sheet, String path) throws IOException {
        wb.write(new FileOutputStream(loadFile(path)));
    }
}
